//
//  Admin_City_CreatDistricViewController.m
//  YunGui
//
//  Created by Hanen 3G 01 on 16/4/5.
//  Copyright © 2016年 hanen. All rights reserved.
//

#import "Admin_City_CreatDistricViewController.h"
#define celllHeight  40.0f
#define sectionHeight 20.0f
#import "PlacePickerView.h"
#import "ChooseCompetitorController.h"
#import "SVProgressHUD.h"
#import "PropertyModel.h"
#import "PropertyViewController.h"
#import <AMapSearchKit/AMapSearchKit.h>
#import "ChooseResonseManController.h"
#import "ZLAlertView.h"
#import "AddVisitViewController.h"
#import "ImageButton.h"

@interface Admin_City_CreatDistricViewController ()<UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource,PropertyViewControllerDelegate,AMapSearchDelegate>
{
    CGFloat   space;
    CGFloat    imageW ;
    UIScrollView   *_scrollView;
    
    UIView *_InfoView;
    UITextField  *_districtNameField;
    ImageButton     *_typeBtn;
    UITextField  *_typeTextFiled; //小区类型
    ImageButton     *_propertyNameBtn;
    UITextField  *_propertyTextFiled;//物业公司
    UITextField  *_responseManField;
    ImageButton     *_chooseResponseManBtn;
    
    UIView    *_addressView;
    ImageButton  *_addressBtn;
    UITextField  *_addressTextFiled;//所属地区
    UITextField  *_detailPlaceTextFiled;
    
    UIView     *_districtInfoView;
    UITextField  *_countTextFiled;
    UITextField  *_allCountTextFiled;
    ImageButton  *_dealTimeBtn;
    UITextField     *_dealTimeTextFiled;//交付时间
    ImageButton  *_levelBtn;
    UITextField  *_levelTextFiled;//等级
    ImageButton  *_competitorBtn;
    UITextField  *_competitorTextFiled;//竞争对手
    UIView    *_addPickView;
    dispatch_queue_t _globleQueue;
    
    
    
    
    UIView *_dateView;
    UIDatePicker *_datePicker;
    
    UIView *_placeView;
    UIPickerView *_placePickerView;
//    PlacePickerView *_placeView;
    
    
    BOOL isType;
    BOOL isResponse;
    NSString *proStr;
    NSString *city;
    NSString *regionStr;
    
    
     AMapSearchAPI *_search;
    CGFloat  lontitu;//经度
    CGFloat  latitu;//纬度
    
    NSInteger  districtID;
    
    int  typeId;
    
    PropertyModel *modelPro;
    
    int  levelID;
  
   
}
@property (nonatomic, strong)  NSArray *typeDict;
@property (nonatomic, strong) UIPickerView *typePicker;

@property (nonatomic, strong) NSMutableArray *allRegionArray;
@property (nonatomic, strong) NSMutableArray *provinceArray;
@property (nonatomic, strong) NSMutableArray *cityArray;
@property (nonatomic, strong) NSMutableArray *regionArray;
@property (nonatomic, strong) NSMutableArray *selectedArray;

@property (nonatomic, strong) NSMutableArray *levelArray;
@property (nonatomic, strong) NSMutableArray *competitorArray;
@property (nonatomic, strong) NSMutableString *str;
@property (nonatomic, strong)  NSMutableString  *competiorID;;
@property (nonatomic, strong) UITextField *responseManField;
@property (nonatomic, strong) NSMutableArray *responseArr;

@property (nonatomic, strong)  NSArray *levelDict;


@end

@implementation Admin_City_CreatDistricViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = GrayBackColor;
    self.navigationItem.title = @"创建小区";
    
    self.navigationItem.leftBarButtonItem = [ViewTool getBarButtonItemWithTarget:self WithString:@"back" WithAction:@selector(goToBack)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(postCreatSubDistrict:)];
    
    
    _search = [[AMapSearchAPI alloc] init];
    _search.delegate = self;
       [self initScrollview];

    space = 10.0f;
    imageW = 20.0f;
    _allRegionArray = [NSMutableArray array];
    _typeDict = [NSMutableArray array];
    _provinceArray = [NSMutableArray array];
    _cityArray = [NSMutableArray array];
    _regionArray = [NSMutableArray array];
    _levelArray = [NSMutableArray array];
    _competitorArray = [NSMutableArray array];
    _selectedArray = [NSMutableArray array];
    _responseArr = [NSMutableArray array];
    
    _globleQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
     [self addTypePickeview];
    [self addPlacePickeView];
    
    dispatch_async(_globleQueue, ^{
        [self getRegionData];//获取地区的数据
    });
    dispatch_async(_globleQueue, ^{
        [self getTypeData];//获取小区类型的数据
    });
    
    if (self.isBusiness) {
        self.responseMan = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
        
        self.responseManID = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
//        [self getResponsManData];
    }else{
//        dispatch_async(_globleQueue, ^{//好像 权限不足
//            [self getResponsManData];//获取小区负责人的数据
//        });
    }
    
    dispatch_async(_globleQueue, ^{
        [self getLevelData];//获取小区等级的数据
    });
    dispatch_async(_globleQueue, ^{
        [self getResponseData];//获取负责人的数据
    });
   
    [self addDistrictInfoView];
    [self addAddressView];
    [self addInfoView];
    [self addDatePick];

    self.responseManID = 0;
    
//获取一些数据
   
}

- (void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response{
    NSLog(@"%lu",(unsigned long)response.geocodes.count);
    if (response.geocodes.count == 0){
        return;
    }
//    NSLog(@"%lu",(unsigned long)response.geocodes.count);
    AMapGeocode *geo = response.geocodes[0];
    lontitu = geo.location.longitude;
    latitu = geo.location.latitude;
    NSLog(@"lontitu  %f lati %f",lontitu,latitu);
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField == _detailPlaceTextFiled && _detailPlaceTextFiled.text != nil) {
        //构造AMapGeocodeSearchRequest对象，address为必选项，city为可选项
        AMapGeocodeSearchRequest *geo = [[AMapGeocodeSearchRequest alloc] init];
        geo.address = [NSString stringWithFormat:@"%@%@",_addressTextFiled.text,_detailPlaceTextFiled.text];
        //发起正向地理编码
        [_search AMapGeocodeSearch: geo];
    }
}
- (void)initScrollview
{
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64)];
    [self.view addSubview:_scrollView];
    
}
- (void)addDistrictInfoView
{
    
        NSArray *titileArray = @[@"小区名称",@"小区类型",@"物业名称",@"负责人"];
        
        NSArray *iamgeArray = @[@"Btn_Normal_Xiaoquming",@"Btn_Normal_Liexing2",@"Btn_Nor_Wuye",@"Btn_Nor_Lianxiren"];
       _InfoView = [[UIView alloc] initWithFrame:CGRectMake(0, _addressView.maxY + sectionHeight, kScreenWidth, celllHeight * titileArray.count)];
        _InfoView.backgroundColor = [UIColor whiteColor];
        [_scrollView addSubview:_InfoView];
        
        
        for (int i = 0; i< titileArray.count; i ++) {
            UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(1.5 * space, space + (celllHeight ) * i, imageW, imageW)];
            imageV.image = [UIImage imageNamed:iamgeArray[i]];
            [_InfoView addSubview:imageV];
            
            UILabel  *label1 = [self getLabelWith:CGRectMake(imageV.maxX + space, imageV.y, 80, 20.0f) WithTitle:titileArray[i] WithFontSize:16.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
            [_InfoView addSubview:label1];
            
            UIView *midLine = [ViewTool getLineViewWith:CGRectMake(label1.x, label1.maxY + space -1, kScreenWidth - label1.x, 1) withBackgroudColor:GRAYLINECOLOR];
            [_InfoView addSubview:midLine];
//            
            if(i == 0){
                _districtNameField = [self addTextFieldWithFrame:CGRectMake(label1.maxX + space, label1.y -space, _InfoView.width - label1.maxX - 2 * space, 40.0f) AndStr:@"必填"];
                [_InfoView addSubview:_districtNameField];
            }
            if (i == 1) {
                
                _typeTextFiled = [self addTextFieldWithFrame:CGRectMake(label1.maxX + space, label1.y-space, _InfoView.width - label1.maxX - 2 * space, 40.0f) AndStr:@"必填"];
                _typeTextFiled.enabled = NO;
                [_InfoView addSubview:_typeTextFiled];
                
                _typeBtn = [[ImageButton alloc] initWithFrame:CGRectMake(kScreenWidth - _typeTextFiled.width, label1.y - space, _typeTextFiled.width, 40)];
                [_typeBtn setImage:[UIImage imageNamed:@"Btn_xiangXia"] forState:UIControlStateNormal];
                _typeBtn.selected = NO;
                _typeBtn.userInteractionEnabled = YES;
                [_typeBtn addTarget:self action:@selector(chooseType:) forControlEvents:UIControlEventTouchUpInside];
                [_InfoView addSubview:_typeBtn];
                
            }
            if (i == 2) {
                
                _propertyTextFiled = [self addTextFieldWithFrame:CGRectMake(label1.maxX + space, label1.y-space, _InfoView.width - label1.maxX - 2 * space, 40.0f) AndStr:@"请填写"];
                _propertyTextFiled.enabled = NO;
                [_InfoView addSubview:_propertyTextFiled];
                
                _propertyNameBtn = [[ImageButton alloc] initWithFrame:CGRectMake(kScreenWidth - _propertyTextFiled.width, label1.y- space, _propertyTextFiled.width, 40)];
//                _propertyNameBtn.backgroundColor = [UIColor redColor];
                [_propertyNameBtn setImage:[UIImage imageNamed:@"Btn_Normal_Sousuoxiaoqu"] forState:UIControlStateNormal];
                _propertyNameBtn.userInteractionEnabled = YES;
                [_propertyNameBtn addTarget:self action:@selector(callPropetyController) forControlEvents:UIControlEventTouchUpInside];
                [_InfoView addSubview:_propertyNameBtn];
                
            }
            if (i == 3) {
                
                _responseManField = [[UITextField alloc] initWithFrame:CGRectMake(label1.maxX + space, label1.y-space, _InfoView.width - label1.maxX - 2 * space, 40.0f)];
                _responseManField.delegate = self;
//                if (self.responseMan) {
//                    _responseManField.text = self.responseMan;
//                }else{
                _responseManField.placeholder = @"请选择";
//                }
                _responseManField.enabled = NO;
                _responseManField.textColor = BLACKCOLOR;
                _responseManField.font = [ViewTool getFont:16.0f];
                [_responseManField setValue:UIColorFromRGB(0xe5e5e5) forKeyPath:@"_placeholderLabel.textColor"];
                [_responseManField setValue:[ViewTool getFont:16.0f] forKeyPath:@"_placeholderLabel.font"];
                [_InfoView addSubview:_responseManField];
            
                _chooseResponseManBtn = [[ImageButton alloc] initWithFrame:CGRectMake(kScreenWidth -_responseManField.width, label1.y - space, _responseManField.width, 40)];
                [_chooseResponseManBtn setImage:[UIImage imageNamed:@"Btn_xiangXia"] forState:UIControlStateNormal];
                _chooseResponseManBtn.selected = NO;
                _chooseResponseManBtn.userInteractionEnabled = YES;
                [_chooseResponseManBtn addTarget:self action:@selector(chooseResponse:) forControlEvents:UIControlEventTouchUpInside];
                [_InfoView addSubview:_chooseResponseManBtn];
            }

        UIView *line1 = [ViewTool getLineViewWith:CGRectMake(0, _InfoView.height -1, kScreenWidth, 1) withBackgroudColor:GRAYLINECOLOR];
        [_InfoView addSubview:line1];
            
     }
}
- (void)callPropetyController
{
    
    PropertyViewController *VC = [[PropertyViewController alloc] init];
    VC.isChoose = YES;
    [self.navigationController pushViewController:VC animated:YES];
    VC.delegate = self;
}

- (void)backTolastView:(PropertyModel *)model{
//    [_propertyNameBtn setTitle:model.title forState:UIControlStateNormal];
    _propertyTextFiled.text = model.title;
    modelPro = model;
}
- (UILabel *)getLabelWith:(CGRect)frame WithTitle:(NSString *)title WithFontSize:(CGFloat)fontSize WithTitleColor:(UIColor *)color WithTextAlignment:(NSTextAlignment )textAlignment
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textColor = color;
    label.textAlignment = textAlignment;
    label.font = [ViewTool getFont:fontSize];
    return label;
}
-(UITextField *)addTextFieldWithFrame:(CGRect)frame AndStr:(NSString *)placeholder
{
    UITextField *textF=[[UITextField alloc]initWithFrame:frame];
    textF.userInteractionEnabled = YES;
    textF.textColor = BLACKCOLOR;
    textF.placeholder=placeholder;
    textF.delegate = self;
    textF.font = [ViewTool getFont:16.0f];
    [textF setValue:UIColorFromRGB(0xe5e5e5) forKeyPath:@"_placeholderLabel.textColor"];
    [textF setValue:[ViewTool getFont:16.0f] forKeyPath:@"_placeholderLabel.font"];
    return textF;
}

#pragma mark --选择类型
- (void)chooseType:(UIButton *)btn
{
    [_districtNameField resignFirstResponder];
    isType = YES;
    isResponse = NO;
    if (btn.selected == NO) {
        [UIView animateWithDuration:0.25 animations:^{
            _addPickView.hidden = NO;
        }];
        
    }else{
        [UIView animateWithDuration:0.25 animations:^{
            _addPickView.hidden = YES;
        }];
    }
    [_typePicker reloadAllComponents];
}
- (void)addAddressView
{
    NSArray *titileArray = @[@"所属地区",@"详细地址"];
    NSArray *imageArray = @[@"Btn_Normal_Diqu",@"Btn_Normal_Didian"];
    _addressView = [[UIView alloc] initWithFrame:CGRectMake(0, _InfoView.maxY + sectionHeight, kScreenWidth, celllHeight * titileArray.count)];
    _addressView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_addressView];
    
    
    for (int i = 0; i< titileArray.count; i ++) {
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(1.5 * space, space + (celllHeight) * i, imageW, imageW)];
        //        imageV.backgroundColor = BlueColor;
        imageV.image = [UIImage imageNamed:imageArray[i]];
        [_addressView addSubview:imageV];
        
        UILabel  *label1 = [self getLabelWith:CGRectMake(imageV.maxX + space, imageV.y, 80, 20.0f) WithTitle:titileArray[i] WithFontSize:16.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
        [_addressView addSubview:label1];
        
        UIView *midLine = [ViewTool getLineViewWith:CGRectMake(label1.x, celllHeight - 1, kScreenWidth - label1.x, 1) withBackgroudColor:GRAYLINECOLOR];
        [_addressView addSubview:midLine];
        
        if(i == 0){
            
            _addressTextFiled = [self addTextFieldWithFrame:CGRectMake(label1.maxX + space, label1.y-space, _addressView.width - label1.maxX - 2 * space, 40.0f) AndStr:@"请填写"];
            _addressTextFiled.enabled = NO;
            [_addressView addSubview:_addressTextFiled];
            
            _addressBtn = [[ImageButton alloc] initWithFrame:CGRectMake(kScreenWidth - _addressTextFiled.width, label1.y- space, _addressTextFiled.width, 40)];
            [_addressBtn setImage:[UIImage imageNamed:@"Btn_xiangXia"] forState:UIControlStateNormal];
            _addressBtn.userInteractionEnabled = YES;
            [_addressBtn addTarget:self action:@selector(callplacePicker:) forControlEvents:UIControlEventTouchUpInside];
            _addressBtn.selected = NO;
            [_addressView addSubview:_addressBtn];
            
        }
        if (i == 1) {
            _detailPlaceTextFiled = [self addTextFieldWithFrame:CGRectMake(label1.maxX + space, label1.y-space, _addressView.width - label1.maxX - 2 * space, 40.0f) AndStr:@"请填写"];
            [_addressView addSubview:_detailPlaceTextFiled];
            
        }
        
    }
    UIView *line1 = [ViewTool getLineViewWith:CGRectMake(0, _addressView.height -1, kScreenWidth, 1) withBackgroudColor:GRAYLINECOLOR];
    [_addressView addSubview:line1];
}

- (void)addInfoView
{
    NSArray *titileArray = @[@"当前户数",@"总户数",@"交付时间",@"等级",@"竞争对手"];
    
    NSArray *iamgeArray = @[@"Btn_Normal_Hushu",@"Btn_Normal_Zongshu",@"Btn_Normal_Jiaofushijian",@"Btn_Normal_Dengji",@"Btn_Nor_Jingzhengduishou"];
    _districtInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, _addressView.maxY + sectionHeight, kScreenWidth, celllHeight * titileArray.count)];
    _districtInfoView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_districtInfoView];
    
    
    for (int i = 0; i< titileArray.count; i ++) {
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(1.5 * space, space+ (celllHeight) * i, imageW, imageW)];
        imageV.image = [UIImage imageNamed:iamgeArray[i]];
        [_districtInfoView addSubview:imageV];
        
        UILabel  *label1 = [self getLabelWith:CGRectMake(imageV.maxX + space, imageV.y, 80, 20.0f) WithTitle:titileArray[i] WithFontSize:16.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
        [_districtInfoView addSubview:label1];
        
        
        
       if (i == 0) {
           
           _countTextFiled = [self addTextFieldWithFrame:CGRectMake(label1.maxX + space, label1.y-space, _addressView.width - label1.maxX - 2 * space, 40.0f) AndStr:@"请填写"];
           _countTextFiled.keyboardType = UIKeyboardTypeNumberPad;
           [_districtInfoView addSubview:_countTextFiled];
           
        }
        if (i == 1) {
            
            _allCountTextFiled = [self addTextFieldWithFrame:CGRectMake(label1.maxX + space, label1.y-space, _addressView.width - label1.maxX - 2 * space, 40.0f) AndStr:@"请填写"];
            _allCountTextFiled.keyboardType = UIKeyboardTypeNumberPad;
            [_districtInfoView addSubview:_allCountTextFiled];
            
        }
        if (i == 2) {
            
            _dealTimeTextFiled = [self addTextFieldWithFrame:CGRectMake(label1.maxX + space, label1.y-space, _addressView.width - label1.maxX - 2 * space, 40.0f) AndStr:@"必填"];
            _dealTimeTextFiled.enabled = NO;
            [_districtInfoView addSubview:_dealTimeTextFiled];
            
            _dealTimeBtn = [[ImageButton alloc] initWithFrame:CGRectMake(kScreenWidth - _dealTimeTextFiled.width, label1.y- space, _dealTimeTextFiled.width, 40)];
//            _dealTimeBtn.backgroundColor = [UIColor redColor];
            [_dealTimeBtn setImage:[UIImage imageNamed:@"Btn_xiangXia"] forState:UIControlStateNormal];
            _dealTimeBtn.userInteractionEnabled = YES;
            _dealTimeBtn.selected = NO;
            [_dealTimeBtn addTarget:self action:@selector(callDataPicker:) forControlEvents:UIControlEventTouchUpInside];
                   
            [_districtInfoView addSubview:_dealTimeBtn];
        }
        if (i == 3) {
            
            _levelTextFiled = [self addTextFieldWithFrame:CGRectMake(label1.maxX + space, label1.y-space, _addressView.width - label1.maxX - 2 * space, 40.0f) AndStr:@"必填"];
            _levelTextFiled.enabled = NO;
            [_districtInfoView addSubview:_levelTextFiled];
            
            _levelBtn = [[ImageButton alloc] initWithFrame:CGRectMake(kScreenWidth -_levelTextFiled.width, label1.y- space, _levelTextFiled.width, 40)];
//            _levelBtn.backgroundColor = [UIColor redColor];
            [_levelBtn setImage:[UIImage imageNamed:@"Btn_xiangXia"] forState:UIControlStateNormal];
            _levelBtn.userInteractionEnabled = YES;
            _levelBtn.selected = NO;
            [_levelBtn addTarget:self action:@selector(callLevelPick:) forControlEvents:UIControlEventTouchUpInside];
            [_districtInfoView addSubview:_levelBtn];
            
        }
        if (i == 4) {
            
            _competitorTextFiled = [self addTextFieldWithFrame:CGRectMake(label1.maxX + space, label1.y-space, _addressView.width - label1.maxX - 2 * space, 40.0f) AndStr:@"必填"];
            _competitorTextFiled.enabled = NO;
            [_districtInfoView addSubview:_competitorTextFiled];
            
            _competitorBtn = [[ImageButton alloc] initWithFrame:CGRectMake(kScreenWidth - _competitorTextFiled.width, label1.y - space, _competitorTextFiled.width, 40)];
//            _competitorBtn.backgroundColor = [UIColor redColor];
            [_competitorBtn setImage:[UIImage imageNamed:@"Btn_Normal_Xiangyou (1)"] forState:UIControlStateNormal];
            _competitorBtn.userInteractionEnabled = YES;
            [_competitorBtn addTarget:self action:@selector(chooseCompetitor:) forControlEvents:UIControlEventTouchUpInside];
            [_districtInfoView addSubview:_competitorBtn];
            
            
        }
        
        UIView *midLine = [ViewTool getLineViewWith:CGRectMake(label1.x, label1.maxY + space -1, kScreenWidth - label1.x, 1) withBackgroudColor:GRAYLINECOLOR];
        [_districtInfoView addSubview:midLine];
        
        if (i == 4) {
            midLine.frame = CGRectMake(0, label1.maxY + space -1, kScreenWidth, 1);
        }
    }
//    UIView *line1 = [ViewTool getLineViewWith:CGRectMake(0, _districtInfoView.height -1, kScreenWidth, 1) withBackgroudColor:GRAYLINECOLOR];
//    [_districtInfoView addSubview:line1];
    
    _scrollView.contentSize = CGSizeMake(kScreenWidth, _districtInfoView.maxY + space);
    
}
- (void)callLevelPick:(UIButton *)btn
{
    isType = NO;
    isResponse = NO;
    if (btn.selected == NO) {
        [UIView animateWithDuration:0.25 animations:^{
            _addPickView.hidden = NO;
        }];
       
    }else{
        [UIView animateWithDuration:0.25 animations:^{
            _addPickView.hidden = YES;
        }];
    }
     [_typePicker reloadAllComponents];
}
#pragma mark --选择竞争对手
- (void)chooseResponse:(UIButton *)btn
{
//    ChooseResonseManController *chooseVC = [[ChooseResonseManController alloc] init];
//    [self.navigationController pushViewController:chooseVC animated:YES];
//    __unsafe_unretained Admin_City_CreatDistricViewController *admiVC = self;
//    chooseVC.block= ^(NSString *realname,NSString *manId){
//        admiVC.responseManField.text = realname;
//         admiVC.responseManID = [manId intValue];
//    };
    
    isType = NO;
    isResponse = YES;
    if (btn.selected == NO) {
        [UIView animateWithDuration:0.25 animations:^{
            _addPickView.hidden = NO;
        }];
        
    }else{
        [UIView animateWithDuration:0.25 animations:^{
            _addPickView.hidden = YES;
        }];
    }
    [_typePicker reloadAllComponents];
    
}

- (void)chooseCompetitor:(UIButton *)btn
{
    ChooseCompetitorController *competitorVC = [[ChooseCompetitorController alloc] init];
    if(_competitorArray.count != 0){
//    __unsafe_unretained Admin_City_CreatDistricViewController *weakSelf = self;
//    NSLog(@"选中的对手个数%ld",weakSelf.competitorArray.count);
        NSMutableArray *addArr = [NSMutableArray array];
        for (NSDictionary *dict  in _competitorArray) {
            [addArr addObject:dict[@"name"]];
        }
        competitorVC.foreArr = addArr;
        competitorVC.foreDictArr = _competitorArray;
    }
    [self.navigationController pushViewController:competitorVC animated:YES];
//    NSMutableString *str = [NSMutableString string];
    __unsafe_unretained Admin_City_CreatDistricViewController *vc = self;
    vc.str = [[NSMutableString alloc] init];
       vc.competiorID  = [[NSMutableString alloc] init];
    competitorVC.blcok = ^(NSArray *arr){
//        NSLog(@"block 的 数组个数%@",arr[0]);
        for (int i = 0; i < arr.count; i++) {
//            NSString *str = [NSMutableString string];
            NSString *string = [NSString stringWithFormat:@"%@,",arr[i][@"name"]];
           [vc.str appendString:string];
            NSString *ids = [NSString stringWithFormat:@"%@,",arr[i][@"id"]];
            [vc.competiorID appendString:ids];
        }
        if(vc.str){
        NSString *finalStr = [vc.str substringToIndex:vc.str.length - 1];
        NSLog(@"竞争对手ids %@",vc.competiorID);
//        [_competitorBtn setTitle:vc.str forState:UIControlStateNormal];
        
        _competitorTextFiled.text = finalStr;
        }
        vc.competitorArray = (NSMutableArray *)arr;
    };
}
#pragma mark --添加 类型选择的pickerview
- (void)addTypePickeview
{
    
    _addPickView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _addPickView.hidden = YES;
    [self.view addSubview:_addPickView];
    
    CGFloat pickerH = 260.0f;
    CGFloat buttonW = 60.0f;
    CGFloat buttonH = 40.0f;
    
    UIView * bgBlackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth,kScreenHeight - pickerH)];
    bgBlackView.backgroundColor = [UIColor blackColor];
    bgBlackView.alpha = 0.6;
    [_addPickView addSubview:bgBlackView];
    
    
    UIView *pView = [[UIView alloc] initWithFrame:CGRectMake(0, bgBlackView.maxY, kScreenWidth, pickerH)];
    pView.backgroundColor = [UIColor whiteColor];
    [_addPickView addSubview:pView];

    UIView *line1 = [ViewTool getLineViewWith:CGRectMake(0, 0 , kScreenWidth, 1) withBackgroudColor:GRAYLINECOLOR];
    [pView addSubview:line1];
    
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, line1.maxY, buttonW, buttonH)];
    [leftBtn setTitle:@"取消" forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(hanldeSelected:) forControlEvents:UIControlEventTouchUpInside];
    [leftBtn setTitleColor:GRAYCOLOR forState:UIControlStateNormal];
    leftBtn.titleLabel.font = [ViewTool getFont:15.0f];
    [pView addSubview:leftBtn];
    
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(pView.width - 10 - buttonW, line1.maxY , buttonW, buttonH)];
    [rightBtn setTitle:@"确定" forState:UIControlStateNormal];
     rightBtn.titleLabel.font = [ViewTool getFont:15.0f];
      [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(hanldeSelected:) forControlEvents:UIControlEventTouchUpInside];
    [pView addSubview:rightBtn];
    
    UIView *line = [ViewTool getLineViewWith:CGRectMake(0, rightBtn.maxY , kScreenWidth, 1) withBackgroudColor:GRAYLINECOLOR];
    [pView addSubview:line];
    
    _typePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, line.maxY  , kScreenWidth, pView.height - 30 -70)];
    [pView addSubview:_typePicker];
    _typePicker.delegate = self;
    _typePicker.dataSource = self;
    
}
#pragma mark --添加 地区选择的pickerview
- (void)addPlacePickeView
{
    
    _placeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _placeView.hidden = YES;
    [self.view addSubview:_placeView];
    
    CGFloat pickerH = 260.0f;
    CGFloat buttonW = 60.0f;
    CGFloat buttonH = 40.0f;
    
    UIView * bgBlackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth,kScreenHeight - pickerH)];
    bgBlackView.backgroundColor = [UIColor blackColor];
    bgBlackView.alpha = 0.6;
    [_placeView addSubview:bgBlackView];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapToHideBlackView:)];
    [bgBlackView addGestureRecognizer:tapGesture];
    
    UIView *pView = [[UIView alloc] initWithFrame:CGRectMake(0, bgBlackView.maxY, kScreenWidth, pickerH)];
    pView.backgroundColor = [UIColor whiteColor];
    [_placeView addSubview:pView];
    
    UIView *line1 = [ViewTool getLineViewWith:CGRectMake(0, 0 , kScreenWidth, 1) withBackgroudColor:GRAYLINECOLOR];
    [pView addSubview:line1];
    
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, line1.maxY, buttonW, buttonH)];
    [leftBtn setTitle:@"取消" forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(hanldePlaceSelected:) forControlEvents:UIControlEventTouchUpInside];
    [leftBtn setTitleColor:GRAYCOLOR forState:UIControlStateNormal];
    leftBtn.titleLabel.font = [ViewTool getFont:15.0f];
    [pView addSubview:leftBtn];
    
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(pView.width - 10 - buttonW, line1.maxY , buttonW, buttonH)];
    [rightBtn setTitle:@"完成" forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [ViewTool getFont:15.0f];
    [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(hanldePlaceSelected:) forControlEvents:UIControlEventTouchUpInside];
    [pView addSubview:rightBtn];
    
    UIView *line = [ViewTool getLineViewWith:CGRectMake(0, rightBtn.maxY , kScreenWidth, 1) withBackgroudColor:GRAYLINECOLOR];
    [pView addSubview:line];
    
    _placePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, line.maxY  , kScreenWidth, pView.height - 30-70)];
    [pView addSubview:_placePickerView];
    _placePickerView.delegate = self;
    _placePickerView.dataSource = self;
    
    
}
- (void)tapToHideBlackView:(UITapGestureRecognizer *)tap{
    
}
- (void)callplacePicker:(UIButton *)btn
{
    if (btn.selected == NO) {
        [UIView animateWithDuration:0.25 animations:^{
            _placeView.hidden = NO;
        }];
    }else{
        [UIView animateWithDuration:0.25 animations:^{
             _placeView.hidden = YES;
        }];
    }
    btn.selected = !btn.selected;
    [_placePickerView reloadAllComponents];
}
- (void)hanldePlaceSelected:(UIButton *)btn
{
    
    _placeView.hidden = YES;
    _addressBtn.selected = NO;
    
    if(self.provinceArray.count >0 ){
        proStr = [self.provinceArray objectAtIndex:[_placePickerView selectedRowInComponent:0]][@"region"];
//        proStr = [DataTool changeType:s];

    }else{
        proStr = @"";
    }
    if (self.cityArray.count > 0 ) {
        city = [self.cityArray objectAtIndex:[_placePickerView selectedRowInComponent:1]][@"region"];
        
    }else{
        city = @"";
    }
    if(self.regionArray.count >0 ){
       regionStr = [self.regionArray objectAtIndex:[_placePickerView selectedRowInComponent:2]][@"region"];
        districtID = [[self.regionArray objectAtIndex:[_placePickerView selectedRowInComponent:2]][@"id"]  integerValue];
        if (districtID == 0) {
            [Tools showMessage:@"请重新选择地区" view:self];
        }
    }else{
        regionStr = @"";
    }
    
    if ([btn.currentTitle isEqualToString:@"完成"]) {
        _addressTextFiled.text =[NSString stringWithFormat:@"%@ %@ %@",proStr,city,regionStr];
    }
    
}
#pragma mark -- 选择 类型等级的 确定 取消按钮
- (void)hanldeSelected:(UIButton *)btn
{
    _addPickView.hidden = YES;
    if ([btn.currentTitle isEqualToString:@"取消"]) {
        if (isResponse) {
            if (_responseArr.count > 0) {
                _responseManField.text = @"";
            }
        }
    }else{
        NSInteger row = [_typePicker selectedRowInComponent:0];
        if (isResponse) {
            if (_responseArr.count > 0) {
                _responseManField.text = _responseArr[row][@"realname"];
                self.responseManID = [_responseArr[row][@"user_id"] intValue];
            }
        }else{
            if (isType) {
                if (_typeDict.count > 0) {
                    _typeTextFiled.text = _typeDict[row][@"title"];
                    typeId = [_typeDict[row][@"id"] intValue];
                }
                
            }else{
                if (_levelArray.count > 0) {
                    if(row == 0){
                        _competitorBtn.userInteractionEnabled = NO;
                        _competitorTextFiled.text = @"";
                    }else{
                       _competitorBtn.userInteractionEnabled = YES;
                    }
                    _levelTextFiled.text = _levelArray[row][@"desc"];
                    levelID = [_levelArray[row][@"id"] intValue];
                }
                
            }
            
        }
 
        }
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    if(pickerView ==_typePicker){
    return 1;
    }else if (pickerView == _placePickerView){
        return 3;
    }
    return 0;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (pickerView == _typePicker) {
        if (isResponse) {
            return _responseArr.count;
        }else{
            if (isType) {
                return _typeDict.count;
            }else{
                return _levelArray.count;
            }
        }
        }else if(pickerView == _placePickerView){
        if (component ==0) {
            return _provinceArray.count;
        }else if(component == 1){
            return _cityArray.count;
        }else{
            return _regionArray.count;
        }
        
    }
    return 0;
   
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (pickerView == _typePicker) {
        if (isResponse) {
            return _responseArr[row][@"realname"];
        }else{
            if (isType) {
                return _typeDict[row][@"title"];
            }else{
                return _levelArray[row][@"desc"];
            }
        }
        
    }else{
        if (component == 0) {
            return _provinceArray[row][@"region"];
        }else if (component == 1) {
            return _cityArray[row][@"region"];
        }else{
            return _regionArray[row][@"region"];
        }
    }
    return nil;
  
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if(pickerView == _typePicker){
        
    }else{
    if (component == 0) {
        _selectedArray = self.provinceArray[row][@"city"];
        if (_selectedArray.count > 0) {
            self.cityArray = _selectedArray;
        }else{
            self.cityArray = nil;
        }
        if (self.cityArray.count > 0) {
            self.regionArray = _cityArray.firstObject[@"district"];
        } else {
            self.regionArray = nil;
        }
    }
    [pickerView selectedRowInComponent:1];
    [pickerView reloadComponent:1];
    [pickerView selectedRowInComponent:2];
    if (component == 1) {
        if (self.selectedArray.count > 0 && self.cityArray.count > 0) {
            self.regionArray = [self.selectedArray objectAtIndex:row][@"district"];
            //   self.cityArray = _provinceArray.firstObject[@"city"];
        } else {
            self.regionArray = nil;
        }
        [pickerView selectRow:0 inComponent:2 animated:YES];
    }
    [pickerView reloadComponent:2];
        
    }
    
    
}
#pragma mark --时间选择
- (void)addDatePick
{
    _dateView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _dateView.hidden = YES;
    [self.view addSubview:_dateView];
    
    CGFloat pickerH = 260.0f;
    
    UIView * bgBlackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth,kScreenHeight - pickerH)];
    bgBlackView.backgroundColor = [UIColor blackColor];
    bgBlackView.alpha = 0.6;
    [_dateView addSubview:bgBlackView];
    
    
    UIView *pView = [[UIView alloc] initWithFrame:CGRectMake(0, bgBlackView.maxY, kScreenWidth, pickerH)];
    pView.backgroundColor = [UIColor whiteColor];
    [_dateView addSubview:pView];

    
    CGFloat buttonW = 60.0f;
    CGFloat buttonH = 40.0f;
    
    UIButton *sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(pView.width - buttonW - 10, 0, buttonW, buttonH)];
    [sureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [sureBtn setTitleColor:BLACKCOLOR forState:UIControlStateNormal];
    [sureBtn addTarget:self action:@selector(clickSure:) forControlEvents:UIControlEventTouchUpInside];
    sureBtn.titleLabel.font= [UIFont systemFontOfSize:14.0f];
    [pView addSubview:sureBtn];
    
    UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, buttonW, buttonH)];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:GRAYCOLOR forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(clickSure:) forControlEvents:UIControlEventTouchUpInside];
    cancelBtn.titleLabel.font= [UIFont systemFontOfSize:14.0f];
    [pView addSubview:cancelBtn];
    
    UIView *line = [ViewTool getLineViewWith:CGRectMake(0, 0, kScreenWidth, 1) withBackgroudColor:GRAYLINECOLOR];
    [pView addSubview:line];
    UIView *line1 = [ViewTool getLineViewWith:CGRectMake(0, cancelBtn.maxY, kScreenWidth, 0.8) withBackgroudColor:GRAYLINECOLOR];
    [pView addSubview:line1];
    
    
    _datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, line1.maxY + 3, pView.width, pView.height - line1.maxY - 3)];
    _datePicker.datePickerMode = UIDatePickerModeDate;
    NSLocale *local = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    _datePicker.locale = local;
    //   NSString * yearStr =  [DateTool getCurrentYears];
    //    int  moreyear = [yearStr intValue] + 1; //当前时间往后一年
    //    int  lessyear = [yearStr intValue] - 1;//当前时间之前一年
    NSDate *currentDate = [NSDate date];
    NSDateFormatter *formate = [[NSDateFormatter alloc] init];
    [formate setDateFormat:@"yyyy-MM-dd HH:mm"];//HH 大写就是24小时制 小写就是12小时制
    
    NSTimeInterval time = 365 * 30 * 24 * 60 * 60;
    NSDate * lastYearDate = [currentDate dateByAddingTimeInterval:-time];
    NSDate * moreYearDate = [currentDate dateByAddingTimeInterval:time];
    
    _datePicker.minimumDate = lastYearDate;//如果其中一个未设置 则默认用户可以选择 之前或未来的任何日期
    _datePicker.maximumDate = moreYearDate;
    [_datePicker setDate:currentDate animated:YES];
    [_datePicker addTarget:self action:@selector(dateChoose:) forControlEvents:UIControlEventValueChanged];
    [pView addSubview:_datePicker];
}
- (void)callDataPicker:(UIButton *)btn
{
    if (btn.selected == NO) {
        
        [UIView animateWithDuration:0.5 animations:^{
            _dateView.hidden = NO;
        }];
    }else{
        
        [UIView animateWithDuration:0.5 animations:^{
            _dateView.hidden = YES;
        }];
    }
    btn.selected = !btn.selected;
}

- (void)clickSure:(UIButton *)btn
{
    _dealTimeBtn.selected = NO;
    _dateView.hidden = YES;
    if ([btn.currentTitle isEqualToString:@"确定"]) {
        NSDateFormatter *formate = [[NSDateFormatter alloc]init];
//        [formate setDateFormat:@"yyyy-MM-dd HH:mm"];
        [formate setDateFormat:@"yyyy-MM-dd"];
        NSString * dateStr = [formate stringFromDate:_datePicker.date];
        
        _dealTimeTextFiled.text = dateStr;
        
    }else{
    }
    
}

- (void)dateChoose:(UIDatePicker *)datePicker
{
    NSDateFormatter *formate = [[NSDateFormatter alloc]init];
//    [formate setDateFormat:@"yyyy-MM-dd HH:mm"];
    [formate setDateFormat:@"yyyy-MM-dd"];
    NSString * dateStr = [formate stringFromDate:_datePicker.date];
    
//    [_dealTimeBtn setTitle:dateStr forState:UIControlStateNormal];
//     [_dealTimeBtn setTitleColor:CreatFontColor forState:UIControlStateNormal];
    _dealTimeTextFiled.text = dateStr;
    
    
}

#pragma mark --获取小区类型
- (void)getTypeData
{
    int isCache;
    NSString *currentTime = [DateTool getCurrentDate];
    NSString *timeString = [[NSUserDefaults standardUserDefaults] objectForKey:@"getTypeTime"];
    NSLog(@"%@%@",currentTime,timeString);
    if (timeString != nil) {
        NSInteger diffTime = [DateTool getTimesDiffTimeFrom:timeString To:currentTime];
        if (diffTime > 24) {
            isCache = 1;
        }else{
            isCache = 0;
        }
    }
    
    [[NSUserDefaults standardUserDefaults] setObject:currentTime forKey:@"getTypeTime"];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:@{@"method" : @"app.village.type",@"isCache" : @(isCache)}];
    
    NSDictionary *parames = [DataTool addSignToDic:dict];
    [DataTool postWithUrl:HEAD_URL parameters:parames success:^(id data) {
        id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
//        NSLog(@"小区类型的数据 :%@",backData);
        _typeDict = backData[@"data"][@"allType"];
        
        [_typePicker reloadAllComponents];
    } fail:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
}
//- (void)getResponsManData
//{
//    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:@{@"method" : @"app.village.officials"}];
//    
//    NSDictionary *parames = [DataTool addSignToDic:dict];
//    [DataTool postWithUrl:HEAD_URL parameters:parames success:^(id data) {
//        id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
//        NSLog(@"小区负责人的数据 :%@",backData);
//        
//    } fail:^(NSError *error) {
//        NSLog(@"%@",error.localizedDescription);
//    }];
//
//
//}
- (void)getRegionData
{
    
    int isCache;
    NSString *currentTime = [DateTool getCurrentDate];
    NSString *timeString = [[NSUserDefaults standardUserDefaults] objectForKey:@"getRegionTime"];
//    NSLog(@"%@%@",currentTime,timeString);
    if (timeString != nil) {
        NSInteger diffTime = [DateTool getTimesDiffTimeFrom:timeString To:currentTime];
        if (diffTime > 24) {
            isCache = 1;
        }else{
            isCache = 0;
        }
    }
    
    [[NSUserDefaults standardUserDefaults] setObject:currentTime forKey:@"getRegionTime"];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:@{@"method" : @"app.region.business.city",@"isCache":@(isCache)}];
    NSDictionary *parames = [DataTool addSignToDic:dict];
    NSLog(@"%@+++++地区类型",parames);
    
    [DataTool postWithUrl:HEAD_URL parameters:parames success:^(id data) {
        id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
        NSLog(@"地区类型的数据 :%@",backData);
        _allRegionArray = backData[@"data"][@"citys"];
        
        for (int i = 0; i<_allRegionArray.count; i++) {
            NSDictionary *provinceDict = _allRegionArray[i];
            if (provinceDict) {
                [_provinceArray addObject:provinceDict];
            }
        
        self.selectedArray = _provinceArray.firstObject[@"city"];
            if (self.selectedArray.count > 0) {
                self.cityArray = _provinceArray.firstObject[@"city"];
            }
            if(self.cityArray.count> 0){
                self.regionArray = self.cityArray.firstObject[@"district"];
            }
        }
        [_placePickerView reloadAllComponents];
        
    } fail:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
}

- (void)getLevelData
{
      int isCache;
    NSString *currentTime = [DateTool getCurrentDate];
    NSString *timeString = [[NSUserDefaults standardUserDefaults] objectForKey:@"getLevelTime"];
    NSLog(@"%@%@",currentTime,timeString);
    if (timeString != nil) {
         NSInteger diffTime = [DateTool getTimesDiffTimeFrom:timeString To:currentTime];
        if (diffTime > 24) {
            isCache = 1;
        }else{
            isCache = 0;
        }
    }
    
    [[NSUserDefaults standardUserDefaults] setObject:currentTime forKey:@"getLevelTime"];
  
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:@{@"method" : @"app.village.level",@"isCache" :@(isCache)}];
    NSDictionary *parames = [DataTool addSignToDic:dict];
    [DataTool postWithUrl:HEAD_URL parameters:parames success:^(id data) {
        id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
//        NSLog(@"小区等级的数据 :%@",backData);
        _levelArray = backData[@"data"][@"allLevel"];
        [_typePicker reloadAllComponents];
        
    } fail:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
}
- (void)getResponseData{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:@{@"method" : @"app.village.officials"}];
    
    NSDictionary *parames = [DataTool addSignToDic:dict];
    [DataTool postWithUrl:HEAD_URL parameters:parames success:^(id data) {
        id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
        
        if ([backData[@"status"] isEqualToString:@"SUCCESS"]) {
            
            NSLog(@"小区负责人的数据 :%@",backData);
            _responseArr = backData[@"data"][@"officials"];
            NSLog(@"%lu",(unsigned long)_responseArr.count);
        }else{
//            [Tools showMessage:@"获取数据失败" view:self];
        }
//        NSLog(@"%@ 负责人获取",backData);
        [_typePicker reloadAllComponents];
        
    } fail:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
//        [Tools showMessage:@"获取数据失败" view:self];
    }];

}

#pragma mark --提交 创建
- (void)postCreatSubDistrict:(UIButton *)btn{

    NSLog(@"%d +++++",self.responseManID);
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"method":@"app.village.store"}];
    
    if (_districtNameField.text.length == 0 ) {
        [self.view makeToast:@"请填写小区名"];
         return;
    }else if (_typeTextFiled.text.length == 0){
        [self.view makeToast:@"请选择类型"];
         return;
    }else if(_propertyTextFiled.text.length == 0){
        [self.view makeToast:@"请填写物业"];
         return;
    }
//    else if(_responseManField.text.length == 0){
//        [self.view makeToast:@"请填写负责人"];
//         return;
//    }
    
    else if (_addressTextFiled.text.length == 0){
       [self.view makeToast:@"请填写地址"];
         return;
    }else if (_detailPlaceTextFiled.text.length == 0){
        [self.view makeToast:@"请填写详细地址"];
         return;
    }else if (_countTextFiled.text.length == 0){
        [self.view makeToast:@"请填当前户数"];
         return;
    }else if (_allCountTextFiled.text.length == 0){
        [self.view makeToast:@"请填写总户数"];
         return;
    }else if (_dealTimeTextFiled.text.length == 0){
        [self.view makeToast:@"请填写交付时间"];
         return;
    }else if (_levelTextFiled.text.length == 0){
        [self.view makeToast:@"请填写等级"];
         return;
    }else if (levelID != 1 && _competitorTextFiled.text.length == 0){
        [self.view makeToast:@"请填写竞争对手"];
        return;
    }else {
        
         [SVProgressHUD showWithStatus:@"提交中"];
        self.navigationItem.rightBarButtonItem = nil;
        //NSString stringWithFormat:@"%@%@",_addressBtn.currentTitle,_detailPlaceTextFiled.text]
        NSString *lon = [NSString stringWithFormat:@"%f",lontitu];
        NSString *lat = [NSString stringWithFormat:@"%f",latitu];
       
        
        //当levelID 不为1 的时候 竞争对手必填的
        if(levelID == 1 && _competitorTextFiled.text.length ==0){//当选择的等级是第一个等级时 竞争对手为不必填的
             [dict setDictionary:@{@"method":@"app.village.store",@"title": _districtNameField.text,@"district_id" : @(districtID),@"type_id":@(typeId),@"address": _detailPlaceTextFiled.text,@"property_id" : @(modelPro.propertyId),@"current" :_countTextFiled.text,@"total" :_allCountTextFiled.text,@"endtime":_dealTimeTextFiled.text,@"longitude":lon,@"latitude":lat,@"level_id":@(levelID),@"m_user_id" : @(self.responseManID)}];
            
        }else{
             NSString *competitorString= [self.competiorID substringToIndex:self.competiorID.length - 1];
        [dict setDictionary:@{@"method":@"app.village.store",@"title": _districtNameField.text,@"district_id" : @(districtID),@"type_id":@(typeId),@"address": _detailPlaceTextFiled.text,@"property_id" : @(modelPro.propertyId),@"current" :_countTextFiled.text,@"total" :_allCountTextFiled.text,@"endtime":_dealTimeTextFiled.text,@"longitude":lon,@"latitude":lat,@"level_id":@(levelID),@"competitor":competitorString,@"m_user_id" : @(self.responseManID)}];
        }
        NSDictionary *d = [DataTool addSignToDic:dict];
        NSLog(@"参数%@",d);
        [DataTool postWithUrl:HEAD_URL parameters:d success:^(id data) {
            
            
         id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
            NSLog(@"backData%@",backData);
            if([backData[@"status"] isEqualToString:@"SUCCESS"]){
                  [_delegate passValue:@"SUCCESS"];
//                [SVProgressHUD showSuccessWithStatus:@"添加成功"];
                [SVProgressHUD dismiss];
                    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(postCreatSubDistrict:)];
                if (_isChooseDistrict == NO) {
//                   [self performSelector:@selector(goToBack) withObject:nil afterDelay:0.1];
                    [self.navigationController popViewControllerAnimated:YES];
                }else{
                    
                    SubDistrictDetailModel *model =  [[SubDistrictDetailModel alloc]init];
                    [model setValuesForKeysWithDictionary:backData];
                    [self.delgate chooseDistrict:model];
                    
                    NSArray *array = self.navigationController.viewControllers;
                    [self.navigationController popToViewController:[array objectAtIndex:(array.count -3)] animated:YES];
                }
            }else{
                [SVProgressHUD dismiss];
                    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(postCreatSubDistrict:)];
                if ([backData[@"msg"] isEqualToString:@"不存在该区县"]) {
                    [Tools showMessage:@"请重新选择地区" view:self];
                }else{
                    [Tools showMessage:backData[@"msg"] view:self];
                }
                
            }
        } fail:^(NSError *error) {
            self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(postCreatSubDistrict:)];
            NSLog(@"%@",error.localizedDescription);
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
            [SVProgressHUD dismiss];
        }];
        
    }//sdf
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)goToBack{
//    
//    UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"是否返回" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"确定", nil];
    ZLAlertView *alert = [[ZLAlertView alloc] initWithTitle:@"提示" message:@"是否需要返回"];
    [alert addBtnTitle:@"取消" action:^{}];
    [alert addBtnTitle:@"确定" action:^{
        [self.navigationController popViewControllerAnimated:YES];
    }];
    [alert showAlertWithSender:self];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
